<template>
    <view class="accumulate-list-item">
        <view class="item-main">
            <image class="image" mode="aspectFill" :src="easyGetImgUrl(item.Images)"></image>
            <view class="info">
                <view class="name">
                    <text class="name-text">{{ item.Name }}</text>
                    <text class="price">价值￥{{ item.ProductPrice }}</text>
                </view>
                <view class="info-main">
                    <view class="progress-box">
                        <view class="percent-tip">
                            <text>已完成</text>
                            <text class="price-text small">¥</text>
                            <text class="price-text">{{ item.CurrentRecord }}</text>
                        </view>
                        <view class="progress">
                            <view class="progress-bar">
                                <view class="percent-bar" :style="{ width: getPercent() }">
                                    <view class="progress-bar-percent"></view>
                                </view>
                                <view class="progress-bar-bg"></view>
                            </view>
                        </view>
                        <text class="tip">购买商品满{{ item.AddupRecord }}元免费送</text>
                    </view>

                    <view class="action">
                        <button class="btn btn-main" v-if="item.State == 0" @click.stop="pay">立即支付</button>
                        <button class="btn btn-main" v-if="item.State == 1" @click.stop="buy">购买商品</button>
                        <button class="btn btn-main-hollow" v-if="item.State == 2">待奖励</button>
                        <button class="btn btn-main-hollow" v-if="item.State == 3">已奖励</button>
                        <button class="btn disable" v-if="item.State == 4" disabled>已取消</button>
                        <button class="btn disable" v-if="item.State == 5" disabled>已过期</button>
                    </view>
                </view>
            </view>
        </view>
        <text class="item-time" v-if="item.State != 4 && item.State != 5"
            >活动时间：{{ item.StartTime }} 至 {{ item.EndTime }}</text
        >
        <text class="item-time" v-if="item.State == 4">活动已取消</text>
        <text class="item-time" v-if="item.State == 5">活动已过期</text>
    </view>
</template>

<script>
export default {
    props: {
        item: {
            type: Object,
            default: () => {},
        },
    },
    components: {},
    data() {
        return {}
    },
    methods: {
        getPercent() {
            let percent = this.item.CurrentRecord / this.item.AddupRecord
            if (percent > 1) {
                return "100%"
            }
            if (percent <= 0.01) {
                return "1%"
            }
            percent = percent * 100 + "%"
            return percent
        },
        buy() {
            this.easyGoTo("/pages_shop/packet/accumulate/list?id=" + this.item.ActivityId)
        },
        pay() {
            this.easyGoTo("/pages_shop/packet/order/orderDetail?id=" + this.item.OrderId)
        },
    },
}
</script>

<style lang="scss">
.accumulate-list-item {
    display: flex;
    flex-direction: column;
    padding: $app-page-padding;
    background: $color-white;
    border-radius: 16rpx;
    margin: 0 1rpx;
    margin-bottom: 12rpx;
    .item-main {
        display: flex;
        flex-direction: row;
        margin-bottom: $app-page-padding;
    }
    .item-time {
        color: #1e1e1e;
        font-size: $font-size-24;
    }
    .image {
        width: 224rpx;
        height: 224rpx;
        border-radius: 8rpx;
        margin-right: $app-page-padding;
    }
    .info {
        display: flex;
        flex-direction: column;
        flex: 1;
        justify-content: space-between;
        .name {
            margin-bottom: 20rpx;
            display: flex;
            flex-direction: column;
            .name-text {
                font-size: $font-size-28;
                font-weight: 700;
                margin-bottom: 8rpx;
            }
            .price {
                color: #cd6300;
                font-size: $font-size-24;
            }
        }
        .info-main {
            display: flex;
            flex-direction: row;

            .progress-box {
                flex: 1;
                display: flex;
                flex-direction: column;
                .percent-tip {
                    margin-bottom: 14rpx;
                }
                .price-text {
                    font-size: $font-size-32;
                }
                .small {
                    font-size: $font-size-24;
                    margin-left: 8rpx;
                }
                .tip {
                    font-size: $font-size-20;
                }
                .progress {
                    margin-bottom: 8rpx;
                }
            }

            .action {
                width: 120rpx;
                // height: 48rpx;
                margin-left: 20rpx;
                display: flex;
                // align-self: center;
                .btn {
                    padding: 0 10rpx;
                    border-radius: 100rpx;
                    min-width: 120rpx;
                }
            }
        }
    }
}

.action {
    margin-top: 10rpx;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-self: flex-end;
}
</style>
